﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using super_scrable.Models;

namespace super_scrable.Views
{
    public partial class DefaultForm : Form
    {
        public DefaultForm()
        {
            InitializeComponent();
            if (!System.IO.Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), super_scrable.Properties.Settings.Default.language_dir)))
            {
                installRequiredFile();
            }
        }

        private void installRequiredFile()
        {
            string app_data_dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string app_dir = Path.Combine(app_data_dir,super_scrable.Properties.Settings.Default.app_dir);
            if (!Directory.Exists(app_dir));
                Directory.CreateDirectory(app_dir);

            string language_dir = Path.Combine(app_data_dir , super_scrable.Properties.Settings.Default.language_dir);
            if (!Directory.Exists(language_dir))
                Directory.CreateDirectory(language_dir);
            
            string default_language = Path.Combine(app_data_dir , super_scrable.Properties.Settings.Default.language_dir + "/words.txt");
            if (!File.Exists(default_language))
                File.Copy("words.txt", default_language);
        }

        private void commencerPartie_Click(object sender, EventArgs e)
        {
            SelectionJoueur fen = new SelectionJoueur();
            if (fen.ShowDialog() == DialogResult.OK)
            {
                //init info party
                GameInfo info = new GameInfo();
                /*info.AddPlayer(new Player("Player1", 0));
                info.AddPlayer(new Player("Player2", 0));*/
                int nb_player = fen.getNbJoueur()+2;
                // On rajoute +2 car l'index est a 0 et le nombre minimum de joueur est 2.
                //info.Nb_player = fen.getNbJoueur()+2;
                for (int i = 0; i < nb_player; i++)
                {
                    info.AddPlayer(new Player("Player "+(i+1), 0));
                }

                this.Visible = false;
                Gameboard game = new Gameboard(info);
                game.Show();
            }            
        }

        private void button_propriete_Click(object sender, EventArgs e)
        {
            Properties prop = new Properties();
            prop.Show();
        }
    }
}
